< previous page page_531 next page >

Page 531
and with more efficiency. For example, don't load modules that you don't need. Visual Basic loads code modules on demand, rather than all at once when the application starts. This means that if you never call a procedure in a module, that module will never be loaded. If your startup form or main form calls procedures in several modules, however, all those modules will be loaded as your application starts and before it's displayed.
The following sections discuss other tips and tricks.
Run a Small Visual Basic Application First
Visual Basic spends a large amount of time during the application startup process simply loading the various runtime DLLs used by Visual Basic, ActiveX, and ActiveX controls. If these are already loaded, however, none of that time would be spent by your application. This means that your application would start up faster if another Visual Basic application was already executing on the computer.
Keep Forms Hidden but Loaded
If you intend to use a form again later in the application process, you might consider hiding the form instead of unloading it. This will keep all the controls and variables in memory so that they don't have to be loaded again when the form is needed. The obvious downside to this technique is the amount of memory used by these forms. If you think that users of your application can afford the memory usage, however, this is an excellent way of having forms appear quickly.
Preload Data
Another way to improve the perceived speed of the application is by preloading any data that it might need. For example, if you need to read several files from disk, it's more efficient to read all the files at once rather than read one, read another, then another, and so on. No matter how fast the computer gets, starting disk access always slows down the process. The time spent loading the additional files will probably go unnoticed by users, and you'll have loaded all the required data.
Getting the Application to Perform Better
Tuning or optimizing an application is a combination of some programming techniques and some common sense. When you get past the obvious things that you can change in the way the application is process (as discussed in the preceding sections), any other changes will take some thought and possibly designtime before you can implement them. An important part of the process is understanding what you can and can't optimize. You can optimize Visual Basic code, processing algorithms, and data access. But you can do nothing about any operation that occurs outside your control, such as network file access.

 
< previous page page_531 next page >

If you like this book, buy it!